const path = require("path");
const isDev = think.env === "development";
const nuxtConfig = require(path.join(think.ROOT_PATH, "client/nuxt.config.js"));
// const nuxt = require('think-nuxt')
// const chinauff = require('../middleware/chinauff')
const nuxt = require("../middleware/nuxt");
const wechat = require("../middleware/wechat");
const token = require("../middleware/token");
module.exports = [
  {
    handle: "meta",
    options: {
      logRequest: isDev,
      sendResponseTime: isDev
    }
  },
  {
    handle: "resource",
    enable: isDev,
    options: {
      root: path.join(think.ROOT_PATH, "www"),
      publicPath: /^\/(static|upload|favicon\.ico)/
    }
  },
  {
    handle: "trace",
    enable: !think.isCli,
    options: {
      debug: isDev
    }
  },
  {
    handle: wechat,
    options: {
      token: "jbh",
      appid: "wxd7075c3232722c89",
      encodingAESKey: ""
    },
    match: /^\/wechat/
  },
  {
    handle: "payload",
    options: {
      keepExtensions: true,
      limit: "5mb"
    }
  },
  {
    handle: token,
    options: {
      unless: [
        "/api/admin/login",
        "/api/cate",
        "/api/config/detail",
        "/api/banner"
      ]
    },
    match: /^\/api/
  },
  {
    handle: "router",
    options: {}
  },
  {
    handle: nuxt,
    options: {
      config: nuxtConfig,
      unless: [/^\/api/, /^\/static/, /^\/upload/, /^\/wechat/, /^\/cli/],
      isDev: isDev
    },
    match: ctx => {
      [/^\/api/, /^\/static/, /^\/upload/, /^\/wechat/, /^\/cli/].forEach(
        reg => {
          if (reg.test(ctx.url)) return false;
        }
      );
      return true;
    }
  },
  "logic",
  "controller"
];
